import { parseEther, parseGwei } from "viem";
import { useSendTransaction, useWaitForTransactionReceipt } from "wagmi";

function SendETH() {
  const { data: hash, sendTransaction } = useSendTransaction();
  const { isLoading: isConfirming, isSuccess: isConfirmed } = useWaitForTransactionReceipt({ hash });

  const handleSend = () => {
    sendTransaction({
      to: "0xd8b934580fcE35a11B58C6D73aDeE468a2833fa8", // 替换为实际接收地址
      value: parseEther("0.01"), // 转换为 Wei
      gasPrice: parseGwei("0"), // 可选 Gas 参数
    });
  };

  return (
    <div style={{ margin: "20px" }}>
      <button onClick={handleSend}>发送 0.01 ETH</button>
      {isConfirming && <span>交易确认中...</span>}
      {isConfirmed && <span>交易成功！哈希：{hash}</span>}
    </div>
  );
}
export default SendETH;
